package lazy2.tool;

import lazy2.util.StringUtil;

public class ColumnDefinition {
	private String  columnName;
	private boolean primaryKey = false;
	private boolean identity = false;
	private String  propertyClassName;
	private String  propertyName;

	public String getColumnName() {
		return columnName;
	}
	public boolean isPrimaryKey() {
		return primaryKey;
	}
	public boolean isIdentity() {
		return identity;
	}
	public String getPropertyClassName() {
		return propertyClassName;
	}
	public String getPropertyName() {
		return propertyName;
	}
	public void setColumnName(String columnName) {
		this.columnName = columnName;
		this.propertyName = dbStringToJavaString(columnName);
	}
	public void setPrimaryKey(boolean primaryKey) {
		this.primaryKey = primaryKey;
	}
	public void setIdentity(boolean identity) {
		this.identity = identity;
	}
	public void setPropertyClassName(String propertyClassName) {
		this.propertyClassName = propertyClassName;
	}
	private static StringBuffer sb = new StringBuffer();
	public static String dbStringToJavaString(String dbString) {
		sb.setLength(0);
		if(dbString!=null) {
			if(dbString.indexOf("_")!=-1) {
				String[] split = dbString.split("_");
				for(int i=0,len=split.length;i<len;i++) {
					if(i==0) {
						sb.append(split[i].toLowerCase());
					} else {
						sb.append(StringUtil.toUpperCase(split[i].toLowerCase(), 0));
					}
				}
			} else {
				if(Character.isLowerCase(dbString.charAt(0))) {
					sb.append(dbString);
				} else {
					sb.append(dbString.toLowerCase());
				}
			}
		}
		return sb.toString();
	}
}
